from .base import TranscriptionObserver

class FileObserver(TranscriptionObserver):
    """文件输出观察者"""
    def __init__(self, file_path: str):
        self.file_path = file_path
        self.buffer = []

    def on_transcription_update(self, text: str, is_final: bool = False):
        self.buffer.append(text)
        if is_final:
            with open(self.file_path, 'w', encoding='utf-8') as f:
                f.write('\n'.join(self.buffer)) 